package com.cmcc.linlaker.ui.query.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cmcc.linlaker.R;
import com.cmcc.linlaker.application.LinhuApp;
import com.cmcc.linlaker.bean.DictBean;
import com.cmcc.linlaker.ui.query.FarmerDetailActivity;
import com.cmcc.linlaker.ui.query.bean.QueryProjectBean;
import com.cmcc.linlaker.utils.DictUtils;

public class FarmerBaseDetailFragment extends Fragment {
    private View fragmentView;

    public static FarmerBaseDetailFragment newInstance() {
        FarmerBaseDetailFragment fragment = new FarmerBaseDetailFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        fragmentView = inflater.inflate(R.layout.fragment_query_farmer_base, container, false);
        initView();
        return fragmentView;
    }

    private TextView text_title, textPhone, textApplyTime, textAddress, textIsControl, textJSXZ, textJSXS, textJZZD, textJZZMJ, textCC, textXMLX, textSSQY;

    private void initView() {
        text_title = fragmentView.findViewById(R.id.text_title);
        textPhone = fragmentView.findViewById(R.id.textPhone);
        textApplyTime = fragmentView.findViewById(R.id.textApplyTime);
        textAddress = fragmentView.findViewById(R.id.textAddress);
        textIsControl = fragmentView.findViewById(R.id.textIsControl);
        textJSXZ = fragmentView.findViewById(R.id.textJSXZ);
        textJSXS = fragmentView.findViewById(R.id.textJSXS);
        textJZZD = fragmentView.findViewById(R.id.textJZZD);
        textJZZMJ = fragmentView.findViewById(R.id.textJZZMJ);
        textCC = fragmentView.findViewById(R.id.textCC);
        textXMLX = fragmentView.findViewById(R.id.textXMLX);
        textSSQY = fragmentView.findViewById(R.id.textSSQY);

        setData();
    }

    private void setData() {
        if (((FarmerDetailActivity) getActivity()).houseDetailData != null) {
            QueryProjectBean.QueryProjectData houseData = ((FarmerDetailActivity) getActivity()).houseDetailData;

            text_title.setText(houseData.name);
            textPhone.setText(getProjectTypeStr(houseData.projectType));
            textApplyTime.setText(houseData.registerTime);
            textAddress.setText(houseData.address);
            textIsControl.setText(DictUtils.getIs(houseData.isControl));
            textJSXS.setText(DictUtils.getForm(houseData.form));
            textJSXZ.setText(DictUtils.getNature(houseData.nature));
            textJZZD.setText(houseData.totalBuildingArea);
            textJZZMJ.setText(houseData.totalLand);
            textCC.setText(houseData.floor);

            textXMLX.setText(DictUtils.getType(houseData.type));
            textSSQY.setText(DictUtils.getRegion(houseData.region));
        }
    }

    private String getProjectTypeStr(String projectType) {
        for (DictBean.DictData bean : LinhuApp.typeList) {
            if (bean.dictValue.equals(projectType)) {
                return bean.dictLabel;
            }
        }
        return "";
    }
}
